package com.cade.agriculturemall.view.personalCenter;

import android.os.Handler;
import android.os.HandlerThread;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.CountCallback;
import com.cade.agriculturemall.base.BasePresenter;
import com.cade.agriculturemall.model.ItemFavouriteEntity;
import com.cade.agriculturemall.model.UserInfoEntity;

/**
 * Created by Lobby on 2017/11/28.
 */

public class PersonalPrensenter extends BasePresenter<PersonalCenterContract.IView> implements PersonalCenterContract.IPresenter {
    private UserInfoEntity mEntity = new UserInfoEntity();

    private Handler delayHandler = new Handler();

    public PersonalPrensenter(PersonalCenterContract.IView view) {
        super(view);
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onCreate() {

    }

    public UserInfoEntity loadPensonalData() {
        AVUser.alwaysUseSubUserClass(UserInfoEntity.class);
        UserInfoEntity user = AVUser.getCurrentUser(UserInfoEntity.class);
        return user;

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void getCollectSize() {
        mView.showProgress();
        AVUser.alwaysUseSubUserClass(UserInfoEntity.class);
        UserInfoEntity user = AVUser.getCurrentUser(UserInfoEntity.class);
        String currentUserId = user.getObjectId();
        AVQuery<ItemFavouriteEntity> avQuery = new AVQuery<>("ItemFavourite");
        avQuery.whereEqualTo("user_Id", currentUserId);
        avQuery.countInBackground(new CountCallback() {
            @Override
            public void done(int i, AVException e) {
                if (e == null) {
                    mView.getCollectSize(i);
                }
                mView.dismissProgress();
            }
        });
    }
}

